Skip to content

add meta parameter for createResourceAt() #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 30, 2020

Conversation

dan12411
Copy link
Contributor

@dan12411 dan12411 commented Jul 30, 2020

close #105 , for add meta parameter for createResourceAt().

@dan12411 dan12411 marked this pull request as draft July 30, 2020 01:39
@dan12411 dan12411 marked this pull request as ready for review July 30, 2020 01:39
@@ -66,7 +66,7 @@ class JsonApiClient {
///
/// https://jsonapi.org/format/#crud-creating
Future<Response<ResourceData>> createResourceAt(Uri uri, Resource resource,
{Map<String, String> headers}) =>
{Map<String, String> headers, Map<String, Object> meta}) =>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the argument is not passed down to _resourceDoc().
Please add a unit test supporting this change. It would belong in this folder https://github.com/f3ath/json-api-dart/tree/master/test/unit/client
You can use the ones that are there already as an example.

Copy link
Contributor Author

@dan12411 dan12411 Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, i will fix it, thank you!

Copy link
Contributor Author

@dan12411 dan12411 Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I use naming documentMeta replace meta? 🤔

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Please disregard that comment. I removed it once realized that resource meta would be in the resource object itself. So just meta is OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get it!

final base = Uri(scheme: 'http', host: host, port: port);
final routing = StandardRouting(base);

group('Client-generated ID', () {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description does not reflect the intention of the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get it!

JsonApiClient client;
RoutingClient routingClient;

setUp(() async {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use this one as the example https://github.com/f3ath/json-api-dart/blob/master/test/unit/client/conrner_cases_test.dart

There is no need to start an actual server for this test. You may use the TestHttpHandler to simulate the response. Then use the TestHttpHandler.requestLog property to validate the request (check that the document actually has the meta property).

I understand it can be confusing. Feel free to reach out if you have questions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I have done with TestHttpHandler. Thanks a lot 👍

expect(request, isNotNull);
expect(request.uri, uri);
expect(request.method, 'POST');
expect(request.body,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave just this expect. The others are unrelated to this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Resource('people', '123', attributes: {'name': 'Te Cheng Hung'});
final meta = {'friend': 'Martin Fowler'};

handler.nextResponse = HttpResponse(500, body: 'Something went wrong');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're testing a successful case, so why use an error response? Why don't we use a simple 201 with no body?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I will fix that, thanks!

@f3ath
Copy link
Owner

f3ath commented Jul 30, 2020

Almost there :)

@f3ath f3ath merged commit 8fb462b into f3ath:master Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

createResourceAt() with meta
2 participants